import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import oracle.Oracle;

import agent.Agent;
import agent.strategy.StrategyManager;
/**
 * The ParamAnalyse routine does a brute force search in StrategyManage parameter space and output the results. 
 * For each parameter, it runs 10 times, each run take 10 rounds, and output the score
 * 
 * @author yutao
 *
 */

public class ParamAnalyse {	
	/** step size for searching in parameter space*/
	private static final double stepSize = 0.5;
	
	public static void main (String [] args) throws IOException{		
		Oracle oracle = new Oracle();
		oracle.pathToWorld = "." + File.separator + "src" + File.separator + "world1" + File.separator;
		String analyseLogPath = "." + File.separator + "src" + File.separator + "log" + File.separator + "analyseLogger.csv";
		//Write the head of analyse log file
		FileWriter logFile = new FileWriter(analyseLogPath);
		BufferedWriter logWriter = new BufferedWriter(logFile);
		logWriter.write("exploreThresh,lookAroundThresh,finalScore"); 
		logWriter.newLine();		
		double finalScore;
		int count = 1;
		for(double exploreThresh=0;exploreThresh<=1;exploreThresh+=stepSize)
		{
			for(double lookAroundThresh=0;lookAroundThresh<=1;lookAroundThresh+=stepSize)
			{
				String agentLogPath = "." + File.separator + "src" + File.separator + "log" + File.separator + "agentLogger" + String.valueOf(count) + ".csv";
				
				//StrategyManager stratagy = new StrategyManager(exploreThresh,lookAroundThresh);
				StrategyManager stratagy = new StrategyManager();

				Agent agent = new Agent(oracle, agentLogPath, stratagy);
				finalScore = agent.play();
				try
				{
					logWriter.write(String.valueOf(exploreThresh)+","+String.valueOf(lookAroundThresh)+","+String.valueOf(finalScore)); 
					logWriter.newLine();
				} catch (IOException e)
				{
					System.err.println("Could not print row to log file");
				}
			}
		}
		try
		{
			logWriter.close();	
		} catch (IOException e)
		{
			System.err.println("Error closing the log file");
		}
	}
}
